// pages/com_active_new/com_active_new.js
const app = getApp();
var router = require("../../router.js");
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    imgUrls: [ //banner图片数据          
    ],
    res_gongsi:'',
    res_geren:'',
    shouye_data:'',
    jieshao_res:'',
    jieshao_ress:'',
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getInfo: function () {
      if (wx.getStorageSync('userInfo')) {
        var that = this;
        app.request({
          url: router.index.index,
          method: "POST",
          data: {
            userId: wx.getStorageSync('userInfo').id,
          },
          success: function (data) {
            if (data.status == true) {
              that.setData({
                user: data.user.type,
                safe: data.safe,
                active_list: data.expand,
                free_active_list: data.free_expand,
                juvenile: data.juvenile,
                //imgUrls: data.banner,
              });
            } else {
              wx.showToast({
                title: '获取信息失败',
                icon: 'none',
                mask: true,
                duration: 2000
              });
            }
          }
        })
      }
    },
  },
  attached() {
    console.log("加载数据")
    // this.getInfo()
    var that = this;
    app.request({
      url: router.course.index,
      method: "POST",
      data: {
        userId: wx.getStorageSync('userInfo').id,
      },
      success: function (data) {
        if (data.res_gongsi.length > 0) {
          for (var i = 0; i < data.res_gongsi.length; i++) {
            data.res_gongsi[i].grade = wx.getStorageSync('grade');
            data.res_gongsi[i].d_type = 2
          }
        }
        if (data.res_geren.length > 0) {
          for (var j = 0; j < data.res_geren.length; j++) {
            data.res_geren[j].grade = wx.getStorageSync('grade');
            data.res_geren[j].d_type = 2
          }
        }
        that.setData({
          imgUrls: data.banner,
          res_gongsi: data.res_gongsi,
          res_geren: data.res_geren,
        });
      }
    })
    app.request({
      url: router.index.event_show,
      method: "POST",
      data: { type_leixing: 2 },
      success: function (res) {
        if (res) {
          that.setData({
            shouye_data: res,
          });
        }
      }
    })
    app.request({
      url: router.index.jieshao,
      method: "POST",
      data: { types: 2 },
      success: function (res) {
        if (res) {
          that.setData({
            jieshao_res: res.res,
            jieshao_ress: res.ress
          });
        }
      }
    })
  },
})
